﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;

namespace TestMembresiaService
{
    
    [TestClass]
    public class TestMembresia
    {
        [TestMethod]
        public void TestEnviarMensaje()
        {
            string postdata = "{\"DscMensaje\":\"Pedido de naranjas\",\"FechMensaje\":\"04/12/2013\",\"CodOfertante\":\"5\",\"CodContratante\":\"4\"}"; //JSON
            byte[] data = Encoding.UTF8.GetBytes(postdata);
            HttpWebRequest req = (HttpWebRequest)WebRequest
                .Create("http://localhost:3191/Membresias.svc/Mensajes");
            req.Method = "POST";
            req.ContentLength = data.Length;
            req.ContentType = "application/json";
            var reqStream = req.GetRequestStream();
            reqStream.Write(data, 0, data.Length);
            var res = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream());
            string alumnoJson = reader.ReadToEnd();
        }

        [TestMethod]
        public void TestListarTodos()
        {

            HttpWebRequest req2 = (HttpWebRequest)WebRequest
                .Create("http://localhost:3191/Membresias.svc/Mensajes/1");
            req2.Method = "GET";
            HttpWebResponse res2 = (HttpWebResponse)req2.GetResponse();
            StreamReader reader2 = new StreamReader(res2.GetResponseStream());
            string alumnoJson2 = reader2.ReadToEnd();
            JavaScriptSerializer js2 = new JavaScriptSerializer();
            List<Mensaje> alumnoObtenido = js2.Deserialize<List<Mensaje>>(alumnoJson2);
            Assert.AreEqual(1, alumnoObtenido.Count);
        }
    }
}
